home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / progutil / stdwin.zoo / test / hello.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-30  |  988 b   |  54 lines

  1. /* The "Hello, world" koan according to David Rosenthal,
  2.    recoded for STDWIN.
  3.    Requirements: print "Hello, world" centered in a window,
  4.    recented after window resizes, redraw after window exposures.
  5.    Check error returns. */
  6.  
  7. #include "stdwin.h"
  8. long _stksize = 16384L;
  9.  
  10. char *string= "Hello, world";
  11.  
  12. int text_h, text_v;
  13.  
  14. placetext(win)
  15.     WINDOW *win;
  16. {
  17.     int width, height;
  18.     wgetwinsize(win, &width, &height);
  19.     text_v= (height - wlineheight()) / 2;
  20.     text_h= (width - wtextwidth(string, -1)) / 2;
  21. }
  22.  
  23. void drawproc(win, left, top, right, bottom)
  24.     WINDOW *win;
  25. {
  26.     wdrawtext(text_h, text_v, string, -1);
  27. }
  28.  
  29. main(argc, argv)
  30.     int argc;
  31.     char **argv;
  32. {
  33.     WINDOW *win;
  34.     winitnew(&argc, &argv);
  35.     win= wopen("Hello", drawproc);
  36.     
  37.     if (win != 0) {
  38.         placetext(win);
  39.         for (;;) {
  40.             EVENT e;
  41.             wgetevent(&e);
  42.             if (e.type == WE_COMMAND &&
  43.                 (e.u.command == WC_CLOSE ||
  44.                  e.u.command == WC_CANCEL))
  45.                 break;
  46.             if (e.type == WE_SIZE)
  47.                 placetext(win);
  48.         }
  49.     }
  50.     
  51.     wdone();
  52.     exit(0);
  53. }
  54.